home *** CD-ROM | disk | FTP | other *** search
/ World of Sound / World of Sound.iso / utils / miditools / kawaied / src / envdisplay1.c < prev    next >
C/C++ Source or Header  |  1992-10-25  |  13KB  |  551 lines

  1. #include "inc.h"
  2. #include "defs.h"
  3. #include "req_manx_5.c"
  4. #include <exec/memory.h>
  5.  
  6. extern int envlevel[4];
  7. extern int envdelay[4];
  8. extern int envattack[4];
  9. extern int envdecay[4];
  10. extern int envsustain[4];
  11. extern int envrelease[4];
  12. extern int mute[4];
  13. extern int sources;
  14.  
  15. int oldenvlevel[4];
  16. int oldenvdelay[4];
  17. int oldenvattack[4];
  18. int oldenvdecay[4];
  19. int oldenvsustain[4];
  20. int oldenvrelease[4];
  21.  
  22. int delx[4],dely[4];
  23. int attx[4],atty[4];
  24. int decx[4],decy[4];
  25. int relx[4],rely[4];
  26. int x1[4],y1[4],x2[4],y2[4],x3[4],y3[4],x4[4],y4[4],x5[4],y5[4];
  27. int X1[4],Y1[4],X2[4],Y2[4],X3[4],Y3[4],X4[4],Y4[4],X5[4],Y5[4];
  28.  
  29. struct Window     *WIN;
  30. struct RastPort *RP;
  31.  
  32. void EnvDisplay(void);
  33. void EnvEdit(int nr);
  34. void BigEnvDisplay(int nr);
  35. void SaveCoord(void);
  36.  
  37. /**********************************************************************************/
  38. /***                                                                            ***/
  39. /**********************************************************************************/
  40.  
  41. void EnvDisplay(void)
  42. {
  43.     int i;
  44.     int x1[4],y1[4],x2[4],y2[4],x3[4],y3[4],x4[4],y4[4],x5[4],y5[4];
  45.     BOOL f;
  46.     
  47.     f=4;
  48.     for (i=0;i<=2*(sources+1)-1;i++)
  49.     {
  50.         if(oldenvlevel[i]    !=    envlevel[i]  )     f=i;
  51.         if(oldenvdelay[i]    !=    envdelay[i]  )    f=i;
  52.         if(oldenvattack[i]    !=    envattack[i] )    f=i;
  53.         if(oldenvdecay[i]    !=    envdecay[i]  )    f=i;
  54.         if(oldenvsustain[i]    !=    envsustain[i])    f=i;
  55.         if(oldenvrelease[i]    !=    envrelease[i])    f=i;
  56.     }
  57.  
  58.     if (f!=4)
  59.     {
  60.         for (i=2*(sources+1)-1;i>=0;i--)
  61.         {        
  62.             x1[i]=260+10*(3-i);                    y1[i]=0;
  63.             x2[i]=x1[i]+envdelay[i]*35/100;        y2[i]=0;
  64.             x3[i]=x2[i]+envattack[i]*40/100;    y3[i]=envlevel[i]*35/100;
  65.             x4[i]=x3[i]+envdecay[i]*40/100;      y4[i]=envsustain[i]*35/100*envlevel[i]/100;
  66.             x5[i]=x4[i]+envrelease[i]*40/100;     y5[i]=0;
  67.         }
  68.  
  69.         SetAPen(rp,0);
  70.         RectFill(rp,261,21,452,74);
  71.         SetAPen(rp,1);
  72.  
  73.         for (i=2*(sources+1)-1;i>=0;i--)
  74.         {    
  75.             int ii=74-5*i;
  76.         
  77.             if (mute[i]!=0) goto Ende;
  78.  
  79.             SetAPen(rp,2);
  80.             AreaMove(rp,x1[i]    ,ii-y1[i]);
  81.             AreaDraw(rp,x2[i]    ,ii-y2[i]);
  82.             AreaDraw(rp,x3[i]    ,ii-y3[i]);
  83.             AreaDraw(rp,x4[i]    ,ii-y4[i]);
  84.             AreaDraw(rp,x5[i]    ,ii-y5[i]);
  85.             AreaEnd(rp);
  86.             SetAPen(rp,1);
  87.  
  88.             Line(win,x1[i]    ,ii-y1[i]    ,x2[i]    ,ii-y2[i]);
  89.             Line(win,x2[i]    ,ii-y2[i]    ,x3[i]    ,ii-y3[i]);
  90.             Line(win,x3[i]    ,ii-y3[i]    ,x4[i]    ,ii-y4[i]);
  91.             Line(win,x4[i]    ,ii-y4[i]    ,x5[i]    ,ii-y5[i]);
  92.             Line(win,x1[i]    ,ii-y1[i]    ,x5[i]    ,ii-y5[i]);
  93.         
  94.             Ende: ;        
  95.         }
  96.     }
  97.     Line(win,261,59,291,74);
  98.  
  99.     for (i=0;i<=2*(sources+1)-1;i++)
  100.     {
  101.         oldenvlevel[i]        = envlevel[i];
  102.         oldenvdelay[i]        = envdelay[i];
  103.         oldenvattack[i]        = envattack[i];
  104.         oldenvdecay[i]        = envdecay[i];
  105.         oldenvsustain[i]    = envsustain[i];
  106.         oldenvrelease[i]    = envrelease[i];
  107.     }
  108. }
  109.  
  110. /**********************************************************************************/
  111. /***                                                                            ***/
  112. /**********************************************************************************/
  113.  
  114. void EnvEdit(int nr)
  115. {
  116.     FILE *fp,*fopen();
  117.     char string[255];
  118.     static struct NewWindow nw;
  119.     struct Gadget *gad;
  120.     int id,i,ii;
  121.     int x,y,xold,yold;
  122.     char *p=(char *)0xbfe001;
  123.  
  124.     int oldenvlevel[4];
  125.     int oldenvdelay[4];
  126.     int oldenvattack[4];
  127.     int oldenvdecay[4];
  128.     int oldenvsustain[4];
  129.     int oldenvrelease[4];
  130.  
  131.     for (i=0;i<=3;i++)
  132.     {
  133.         oldenvlevel[i]=envlevel[i];
  134.         oldenvdelay[i]=envdelay[i];
  135.         oldenvattack[i]=envattack[i];
  136.         oldenvdecay[i]=envdecay[i];
  137.         oldenvsustain[i]=envsustain[i];
  138.         oldenvrelease[i]=envrelease[i];
  139.     }    
  140.  
  141.     nw.Width = 620;
  142.     nw.Height = 110+100*sources;
  143.     nw.DetailPen = 0;
  144.     nw.BlockPen = 1;
  145.     nw.Title ="KAWAI K1-II Librarian...Graphic Envelope Editor";
  146.     nw.Flags=RMBTRAP|ACTIVATE|REPORTMOUSE|SMART_REFRESH|WINDOWDRAG|WINDOWCLOSE|(SCREEN==0 ? WINDOWDEPTH : NULL);
  147.     nw.IDCMPFlags = MOUSEBUTTONS|GADGETUP|GADGETDOWN|CLOSEWINDOW|MOUSEMOVE;
  148.     nw.Type = (SCREEN != 0 ? CUSTOMSCREEN : WBENCHSCREEN);
  149.     nw.CheckMark = NULL;
  150.     nw.NextGadget=NULL;
  151.     nw.Screen = (SCREEN != 0 ? scr : NULL);
  152.     nw.BitMap = NULL;
  153.     nw.MinWidth = 0;
  154.     nw.MinHeight = 0;
  155.     nw.MaxWidth = 0;
  156.     nw.MaxHeight = 0;    
  157.     nw.LeftEdge = 10;
  158.     nw.TopEdge = 10;
  159.  
  160.     WIN=(struct Window *) OpenWindow(&nw);
  161.     if (WIN==NULL) Error("Can't open EnvEdit-window");
  162.     RP=WIN->RPort;
  163.     SetFont(RP,textfont);
  164.  
  165.     /* Setup window */
  166.     SetAPen(RP,1);
  167.  
  168.     Print(WIN,13,103+100*sources,"Undo");
  169.     MakeDBox(WIN,10,95+100*sources,50,105+100*sources);
  170.  
  171.     MakeBox(WIN,100,20,300,90);     MakeBox(WIN,400,20,600,90); 
  172.     if (sources==1)
  173.     {
  174.         MakeBox(WIN,100,120,300,190);     MakeBox(WIN,400,120,600,190); 
  175.     }
  176.  
  177.     for (i=0;i<=2*(sources+1)-1+(sources==0 ? 1 : 0);i++) BigEnvDisplay(i);    
  178.     
  179.  
  180. Loop: WIN->IDCMPFlags = CLOSEWINDOW|MOUSEBUTTONS;
  181.     WaitPort(WIN->UserPort);
  182.  
  183.     while(mesg = (struct IntuiMessage *) GetMsg(WIN->UserPort))
  184.     {
  185.         class=mesg->Class; 
  186.         code=mesg->Code;
  187.         x=mesg->MouseX;
  188.         y=mesg->MouseY;
  189.         if (class==GADGETUP || class==GADGETDOWN)
  190.         {
  191.             gad=mesg->IAddress;
  192.             id=gad->GadgetID;
  193.         }
  194.         ReplyMsg((struct Message *)mesg);
  195.         WIN->IDCMPFlags= NULL;;
  196.     
  197.         for (i=0;i<=3;i++)
  198.         {
  199.             X1[i]=x1[i];     Y1[i]=y1[i];
  200.             X2[i]=x2[i];    Y2[i]=y2[i];
  201.             X3[i]=x3[i];    Y3[i]=y3[i];
  202.             X4[i]=x4[i];    Y4[i]=y4[i];
  203.             X5[i]=x5[i];    Y5[i]=y5[i];
  204.         }
  205.     
  206.         switch(class)
  207.         {
  208.             case CLOSEWINDOW:
  209.             {
  210.                 CloseWindow(WIN);
  211.                 return();
  212.                 break;
  213.             }
  214.         }
  215.     
  216.         if (x>=10 && x<=50 && y>=95+100*sources && y<=105+100*sources)    /* Undo */
  217.         {
  218.             if (MyReq("Are you shure ?"," Yes ","Oh no"))
  219.             {
  220.                 for (i=0;i<=3;i++)
  221.                 {
  222.                     envlevel[i]        =oldenvlevel[i];
  223.                     envdelay[i]        =oldenvdelay[i];
  224.                     envattack[i]    =oldenvattack[i];
  225.                     envdecay[i]        =oldenvdecay[i];
  226.                     envsustain[i]    =oldenvsustain[i];
  227.                     envrelease[i]    =oldenvrelease[i];
  228.                     BigEnvDisplay(i);
  229.                 }
  230.                 TransmitSingleSound(nr);
  231.             }    
  232.         }    
  233.     
  234.  
  235.         if (*p != -4)
  236.         {
  237.             printf("%d\n", *p);
  238.  
  239.             if ((i=CheckDelay(x,y))>=0)
  240.             {
  241.                 int val;
  242.     
  243.                 if (i==1 || i==3) x-=400;
  244.                             else  x-=100;
  245.     
  246.                 if (i==2 || i==3) y-=120;
  247.                             else  y-=30;                
  248.     
  249.                 while(*p != -4)
  250.                 {    
  251.                     SaveCoord();
  252.                     xold=val;
  253.                     x=WIN->MouseX;
  254.                     y=WIN->MouseY;
  255.                     
  256.                     if (i==1 || i==3) x-=400;
  257.                                 else  x-=100;
  258.     
  259.                     if (i==2 || i==3) y-=140;    
  260.                                 else  y-=30;                
  261.     
  262.                     val=2*x;            
  263.                     if (val>=100) val=100;
  264.                     if (val<=0)  val=0;
  265.                     envdelay[i]=val;
  266.                     if (xold != val)
  267.                     {
  268.                          BigEnvDisplay(i);
  269.                         SingleParameterSend(42,i,envdelay[i]);
  270.                     }
  271.                 } 
  272.             }        
  273.     
  274.             if ((i=CheckAttack(x,y))>=0)
  275.             {
  276.                 int valx,valy;
  277.     
  278.                 if (i==1 || i==3) x-=400;
  279.                             else  x-=100;
  280.     
  281.                 if (i==2 || i==3) y-=130;
  282.                             else  y-=30;                
  283.     
  284.                 while(*p != -4)
  285.                 {    
  286.                     SaveCoord();
  287.                     xold=valx;
  288.                     yold=valy;
  289.                     x=WIN->MouseX;
  290.                     y=WIN->MouseY;
  291.                     
  292.                     if (i==1 || i==3) x-=400;
  293.                                 else  x-=100;
  294.                     x=x-envdelay[i]/2;
  295.                     
  296.                     if (i==2 || i==3) y-=130;    
  297.                                 else  y-=30;                
  298.         
  299.                     valx=x*2;    
  300.                     valy=100-y*100/60;        
  301.                     if (valx>=100) valx=100;
  302.                     if (valx<=0)  valx=0;
  303.                     if (valy>=100) valy=100;
  304.                     if (valy<=0)  valy=0;
  305.                     envattack[i]=valx;
  306.                     envlevel[i]=valy;
  307.                     if (xold != valx || yold !=valy)
  308.                     {
  309.                         BigEnvDisplay(i);
  310.                         SingleParameterSend(43,i,envattack[i]);
  311.                         SingleParameterSend(41,i,envlevel[i]);
  312.                     }
  313.                 } 
  314.             }        
  315.     
  316.             if ((i=CheckDecay(x,y))>=0)
  317.             {
  318.                 int valx,valy;
  319.     
  320.                 if (i==1 || i==3) x-=400;
  321.                             else  x-=100;
  322.     
  323.                 if (i==2 || i==3) y-=130;
  324.                             else  y-=30;                
  325.     
  326.                 while(*p != -4)
  327.                 {    
  328.                     SaveCoord();
  329.                     xold=valx;
  330.                     yold=valy;
  331.                     x=WIN->MouseX;
  332.                     y=WIN->MouseY;
  333.                     
  334.                     if (i==1 || i==3) x-=400;
  335.                                 else  x-=100;
  336.                     x=x-envdelay[i]/2-envattack[i]/2;
  337.                     
  338.                     if (i==2 || i==3) y-=130;    
  339.                                 else  y-=30;                
  340.     
  341.                     valx=x*2;
  342.                     valy=(envlevel[i] != 0 ? (100-y*100/60)*100/envlevel[i] : 0);    
  343.                     if (valx>=100) valx=100;
  344.                     if (valx<=0)  valx=0;
  345.                     if (valy>=100) valy=100;
  346.                     if (valy<=0)  valy=0;
  347.                     envdecay[i]=valx;
  348.                     envsustain[i]=valy;
  349.                     if (xold != valx || yold !=valy) 
  350.                     {
  351.                         BigEnvDisplay(i);
  352.                         SingleParameterSend(44,i,envdecay[i]);
  353.                         SingleParameterSend(45,i,envsustain[i]);
  354.                     }
  355.                 }
  356.             }        
  357.     
  358.             if ((i=CheckRelease(x,y))>=0)
  359.             {
  360.                 int valx,valy;
  361.     
  362.                 if (i==1 || i==3) x-=400;
  363.                             else  x-=100;
  364.     
  365.                 if (i==2 || i==3) y-=130;
  366.                             else  y-=30;                
  367.     
  368.                 while(*p != -4)
  369.                 {    
  370.                     SaveCoord();
  371.                     xold=valx;
  372.                     yold=valy;
  373.                     x=WIN->MouseX;
  374.                     y=WIN->MouseY;
  375.                     
  376.                     if (i==1 || i==3) x-=400;
  377.                                 else  x-=100;
  378.                     x=x-envdelay[i]/2-envattack[i]/2-envdecay[i]/2;
  379.                     
  380.                     if (i==2 || i==3) y-=130;    
  381.                                 else  y-=30;                
  382.     
  383.                     valx=x*2;
  384.                     if (valx>=100) valx=100;
  385.                     if (valx<=0)  valx=0;
  386.                     envrelease[i]=valx;
  387.                     if (xold != valx || yold !=valy)
  388.                     { 
  389.                         BigEnvDisplay(i);
  390.                         SingleParameterSend(46,i,envrelease[i]);
  391.                     }
  392.                 }
  393.             }        
  394.         }
  395.     }
  396. goto Loop;
  397.  
  398. Loop1:    CloseWindow(WIN);
  399. }
  400.  
  401. /**********************************************************************************/
  402. /***                                                                            ***/
  403. /**********************************************************************************/
  404.  
  405. int CheckDelay(int x, int y)
  406. {
  407.     int i;
  408.  
  409.     for (i=0;i<=3;i++)
  410.     {
  411.         if (x<=delx[i]+0 && x>=delx[i]-7 && y<dely[i]+3 && y>dely[i]-3) return(i);
  412.     }
  413.     return(-1);
  414. }
  415.  
  416. /**********************************************************************************/
  417. /***                                                                            ***/
  418. /**********************************************************************************/
  419.  
  420. int CheckAttack(int x, int y)
  421. {
  422.     int i;
  423.  
  424.     for (i=0;i<=3;i++)
  425.     {
  426.         if (x<=attx[i]+2 && x>=attx[i]-5 && y<atty[i]+3 && y>atty[i]-3) return(i);
  427.     }
  428.     return(-1);
  429. }
  430.  
  431. /**********************************************************************************/
  432. /***                                                                            ***/
  433. /**********************************************************************************/
  434.  
  435. int CheckDecay(int x, int y)
  436. {
  437.     int i;
  438.  
  439.     for (i=0;i<=3;i++)
  440.     {
  441.         if (x<=decx[i]+5 && x>=decx[i]-1 && y<decy[i]+3 && y>decy[i]-3) return(i);
  442.     }
  443.     return(-1);
  444. }
  445.  
  446. /**********************************************************************************/
  447. /***                                                                            ***/
  448. /**********************************************************************************/
  449.  
  450. int CheckRelease(int x, int y)
  451. {
  452.     int i;
  453.  
  454.     for (i=0;i<=3;i++)
  455.     {
  456.         if (x<=relx[i]+7 && x>=relx[i]-0 && y<rely[i]+3 && y>rely[i]-3) return(i);
  457.     }
  458.     return(-1);
  459. }
  460.  
  461. /**********************************************************************************/
  462. /***                                                                            ***/
  463. /**********************************************************************************/
  464.  
  465. void BigEnvDisplay(int i)
  466. {
  467.     char string[255];
  468.     int ii;
  469.         
  470.     SetAPen(RP,0);
  471.     SetBPen(RP,0);
  472.     Line(WIN,X1[i]    ,Y1[i]    ,X2[i]    ,Y2[i]);
  473.     Line(WIN,X2[i]    ,Y2[i]    ,X3[i]    ,Y3[i]);
  474.     Line(WIN,X3[i]    ,Y3[i]    ,X4[i]    ,Y4[i]);
  475.     Line(WIN,X4[i]    ,Y4[i]    ,X5[i]    ,Y5[i]);
  476.  
  477.     MakeBox(WIN,X2[i]-7,Y2[i]-3,X2[i]+0,Y2[i]+3);
  478.     MakeBox(WIN,X3[i]-5,Y3[i]-3,X3[i]+2,Y3[i]+3);
  479.     MakeBox(WIN,X4[i]-1,Y4[i]-3,X4[i]+5,Y4[i]+3);
  480.     MakeBox(WIN,X5[i]-0,Y5[i]-3,X5[i]+7,Y5[i]+3);
  481.     SetAPen(RP,1);
  482.  
  483.     SetAPen(RP,1);
  484.  
  485.     if (i==0) MakeBox(WIN,100,20,300,90);
  486.     if (i==1) MakeBox(WIN,400,20,600,90); 
  487.     if (i==2) MakeBox(WIN,100,120,300,190);
  488.     if (i==3) MakeBox(WIN,400,120,600,190); 
  489.     
  490.     ii=90+100*(i/2);
  491.  
  492.     x1[i]=300*(i%2)+100;                y1[i]=ii;
  493.     x2[i]=x1[i]+envdelay[i]*50/100;        y2[i]=ii;
  494.     x3[i]=x2[i]+envattack[i]*50/100;    y3[i]=ii-envlevel[i]*60/100;
  495.     x4[i]=x3[i]+envdecay[i]*50/100;        y4[i]=ii-envsustain[i]*60/100*envlevel[i]/100;
  496.     x5[i]=x4[i]+envrelease[i]*50/100;     y5[i]=ii;
  497.  
  498.     delx[i]=x2[i];    dely[i]=y2[i];
  499.     attx[i]=x3[i];    atty[i]=y3[i];
  500.     decx[i]=x4[i];    decy[i]=y4[i];
  501.     relx[i]=x5[i];    rely[i]=y5[i];
  502.  
  503.     Line(WIN,x1[i]    ,y1[i]    ,x2[i]    ,y2[i]);
  504.     Line(WIN,x2[i]    ,y2[i]    ,x3[i]    ,y3[i]);
  505.     Line(WIN,x3[i]    ,y3[i]    ,x4[i]    ,y4[i]);
  506.     Line(WIN,x4[i]    ,y4[i]    ,x5[i]    ,y5[i]);
  507.  
  508.     SetAPen(RP,2);
  509.     MakeBox(WIN,x2[i]-7,y2[i]-3,x2[i]+0,y2[i]+3);
  510.     MakeBox(WIN,x3[i]-5,y3[i]-3,x3[i]+2,y3[i]+3);
  511.     MakeBox(WIN,x4[i]-1,y4[i]-3,x4[i]+5,y4[i]+3);
  512.     MakeBox(WIN,x5[i]-0,y5[i]-3,x5[i]+7,y5[i]+3);
  513.  
  514.     sprintf(string,"Env #%d",i+1);
  515.     Print(WIN,175+300*(i%2),18+100*(i/2),string);
  516.  
  517.     sprintf(string,"Del: %3d",envdelay[i]);
  518.     ColPrint(WIN,10+300*(i%2),30+100*(i/2)-2,string);
  519.     sprintf(string,"Att: %3d",envattack[i]);
  520.     ColPrint(WIN,10+300*(i%2),40+100*(i/2)-2,string);
  521.     sprintf(string,"Dec: %3d",envdecay[i]);
  522.     ColPrint(WIN,10+300*(i%2),50+100*(i/2)-2,string);
  523.     sprintf(string,"Sus: %3d",envsustain[i]);
  524.     ColPrint(WIN,10+300*(i%2),60+100*(i/2)-2,string);
  525.     sprintf(string,"Rel: %3d",envrelease[i]);
  526.     ColPrint(WIN,10+300*(i%2),70+100*(i/2)-2,string);
  527.     sprintf(string,"Lev: %3d",envlevel[i]);
  528.     ColPrint(WIN,10+300*(i%2),80+100*(i/2)-2,string);
  529.     if (mute[i]==1)    ColPrint(WIN,10+300*(i%2),90+100*(i/2)-2,"OFF");
  530.     
  531.     SetAPen(RP,1);
  532. }
  533.  
  534. /**********************************************************************************/
  535. /***                                                                            ***/
  536. /**********************************************************************************/
  537.  
  538. void SaveCoord(void)
  539. {
  540.     int i;
  541.     
  542.     for (i=0;i<=3;i++)
  543.     {
  544.         X1[i]=x1[i];     Y1[i]=y1[i];
  545.         X2[i]=x2[i];    Y2[i]=y2[i];
  546.         X3[i]=x3[i];    Y3[i]=y3[i];
  547.         X4[i]=x4[i];    Y4[i]=y4[i];
  548.         X5[i]=x5[i];    Y5[i]=y5[i];
  549.     }
  550. }
  551.